home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CLASSSRC.PAK / MEMORY.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  2KB  |  102 lines

  1. //----------------------------------------------------------------------------
  2. // Borland Services Library
  3. // Copyright (c) 1993, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   5.7  $
  6. //
  7. // Implementation of memory manipulation functions
  8. //----------------------------------------------------------------------------
  9. #include <winsys/pch.h>
  10. #include <services/memory.h>
  11. #include <classlib/stdtempl.h>
  12. #include <tchar.h>
  13.  
  14. //
  15. // Make a duplicate of a 0-terminated string using new char[]
  16. //
  17. _TCHAR* _SVCSFUNC
  18. strnewdup(const _TCHAR* s, size_t allocSize)
  19. {
  20.   if (!s)
  21.     s = "";
  22.   int alloc = max(_tcslen(s)+1, allocSize);
  23.   return _tcscpy(new _TCHAR[alloc], s);
  24. }
  25.  
  26. //
  27. // Make a far duplicate of a 0-terminated string using new char[] far
  28. //
  29. #if defined(BI_DATA_NEAR)
  30.  
  31. _TCHAR far*  _SVCSFUNC
  32. strnewdup(const _TCHAR far* s, size_t allocSize)
  33. {
  34.   if (!s)
  35.     s = "";
  36.   int alloc = max(_tcslen(s)+1, allocSize);
  37.   return _tcscpy(new far _TCHAR[alloc], s);
  38. }
  39.  
  40. _TCHAR*  _SVCSFUNC
  41. nstrnewdup(const _TCHAR far* s, size_t allocSize)
  42. {
  43.   if (!s)
  44.     s = "";
  45.   int alloc = max(_tcslen(s)+1, allocSize);
  46.   _TCHAR* dst = new _TCHAR[alloc];
  47.   _tcscpy(dst, s);
  48.   return dst;
  49. }
  50.  
  51. long
  52. atol(const _TCHAR far* s)
  53. {
  54.   long val;
  55.   for (val = 0; *s && _istdigit(*s); s++)
  56.     val = val*10 + *s - '0';
  57.   return val;
  58. }
  59.  
  60. #endif
  61.  
  62. //
  63. #if !defined(BI_PLAT_WIN16)
  64.  
  65. //
  66. // Make a duplicate of a wide 0-terminated string using new wchar_t[]
  67. //
  68. wchar_t* _SVCSFUNC
  69. strnewdup(const wchar_t* s, size_t allocSize)
  70. {
  71.   if (!s)
  72.     s = L"";
  73.   int alloc = max((size_t)_tcslen(s)+1, allocSize);
  74.   return _tcscpy(new wchar_t[alloc], s);
  75. }
  76.  
  77. //
  78. // Wide string copy function.
  79. //
  80. wchar_t* _SVCSFUNC
  81. _tcscpy(wchar_t* dst, const wchar_t* src)
  82. {
  83.   wchar_t* p = dst;
  84.   while ((*p++ = *src++) != 0)
  85.     ;
  86.   return dst;
  87. }
  88.  
  89. //
  90. // Wide string length function.
  91. //
  92. size_t _SVCSFUNC
  93. _tcslen(const wchar_t* str)
  94. {
  95.   const wchar_t* p = str;
  96.   for (; *p; p++)
  97.     ;
  98.   return p - str;
  99. }
  100.  
  101. #endif
  102.